<?php
/**
 * 
 */

/**
 * 
 */

/**
 * RSS Feed Class
 *
 * @author anthony
 */
class RSSFeed {
    protected $feed_title = false;
    protected $feed_link = false;
    protected $feed_description = false;
    protected $feed_language = "en-us";
    protected $copyright = false;
    
    protected $item_htmls = "";
    
    /**
     * Constructor for the class and for the feed
     * @param string $feed_title
     * @param string $feed_link
     * @param string $feed_description
     * @param string $feed_copyright
     * @param string $feed_language 
     */
    public function __construct($feed_title, $feed_link, $feed_description, $feed_copyright, $feed_language = false) {
	if($feed_language !== false) {
	    $this->feed_language = $feed_language;
	}
	$this->feed_title = $feed_title;
	$this->feed_link = $feed_link;
	$this->feed_description = $feed_description;
	$this->feed_copyright = $feed_copyright;
    }
    
    /**
     * Destructor for this class 
     */
    public function __destruct() {}
    
    /**
     * Add an item to the feed
     * @param string $title
     * @param string $description
     * @param string $link
     * @param string $pubDate 
     */
    public function addItem($title, $description, $link, $pubDate) {
	$this->item_htmls .= <<<EOIHTML
	    <item>
		<title>{$title}</title>
		<description>{$description}</description>
		<link>{$link}</link>
		<pubDate>{$pubDate}</pubDate>
	    </item>
EOIHTML;
    }
    
    /**
     * Render the RSS feed to the OB. 
     */
    public function render() {
	echo <<<EORENDER
	    <?xml version="1.0" encoding="ISO-8859-1"?>
		<rss version="2.0">
		    <channel>
			<title>{$this->feed_title}</title>
			<link>{$this->feed_link}</link>
			<description>{$this->feed_description}</description>
			<language>{$this->feed_language}</language>
			<copyright>{$this->feed_copyright}</copyright>
			    
			{$this->item_htmls}
			    
		    </channel>
		</rss>
EORENDER;
    }
}

?>
